<template>
  <view
    class="content"
    :style="{
      'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        top: statusBarHeight + 'px',
        background: isHeadBack ? 'rgba(0,0,0,0.3)' : 'rgba(0,0,0,0)',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#EEEEEE"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text"> 客服中心 </view>
    </view>

    <view class="tab_view">
      <u-tabs
        lineWidth="40"
        lineColor="#EEEEEE"
        :activeStyle="{
          color: '#EEEEEE',
          height: '48rpx',
          'line-height': '48rpx',
          'text-align': 'center',
          margin: '0 25rpx',
          'font-size': '34rpx',
        }"
        :inactiveStyle="{
          color: '#ADADAD',
          height: '48rpx',
          'line-height': '48rpx',
          'text-align': 'center',
          margin: '0 25rpx',
          'font-size': '34rpx',
        }"
        item-width="166"
        :list="list"
        :current="listIndex"
        @change="changeList"
      ></u-tabs>
    </view>

    <scroll-view
      scroll-y="true"
      class="box"
      :style="{
        height: scrollHeihgt + 'px',
      }"
      @scroll="scroll"
      @scrolltolower="scrolltolower"
    >
      <view class="box_view">
        <view
          class="box_item"
          v-for="(item, index) in changList"
          :key="index"
          @click="goDetail(item)"
        >
          {{ index + 1 }}.{{ item.title }}
        </view>
      </view>
      <view :style="{height:'100rpx'}"></view>

      <view class="empty_view" v-if="changList && changList.length == 0">
        <image
          class="item_left_clickable"
          src="@/static/images/my/kong.png"
          mode=""
        ></image>
        <view>当前没有相关数据，请查看其他分类或功能。~</view>
      </view>
    </scroll-view>

    <view class="bottom">
      <view class="bottom_btn" @click="goFeed">意见反馈</view>
    </view>

    <floatingBall></floatingBall>
  </view>
</template>
      
      <script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      isHeadBack: false,
      list: [
        {
          name: "常见问题",
          str: "changjian",
        },
        {
          name: "会员问题",
          str: "huiyuan",
        },
        {
          name: "账号问题",
          str: "zhanghao",
        },
        {
          name: "游学问题",
          str: "youxue",
        },
      ],
      listIndex: 0,
      scrollHeihgt: 0,
      changList: [],
      phone:'',
      page:1,
      last_page:0
    };
  },
  created() {
    const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    const windowHeihgt = statusBarHeight.windowHeight;
    this.statusBarHeight = statusBarHeight.statusBarHeight;
    this.$nextTick(() => {
      uni
        .createSelectorQuery()
        .select(".head")
        .boundingClientRect((data) => {
          this.height = data.height;
        })
        .exec();
    });

    this.$nextTick(() => {
      const query = uni.createSelectorQuery().in(this);
      query.select(".head").fields({
        size: true,
      });
      query.select(".tab_view").fields({
        size: true,
      });

      query.exec((data) => {
        let sum = 0;
        data.forEach((item) => {
          sum += item.height;
        });
        this.scrollHeihgt = windowHeihgt - sum - this.statusBarHeight;
      });
    });
    this.getChangList(1);
  },
  methods: {
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },

    scroll(e) {
      if (e.target.scrollTop == 0) {
        this.isHeadBack = false;
      } else {
        this.isHeadBack = true;
      }
    },

    scrolltolower() {
      if (this.page == this.last_page || this.last_page == 0) {
      } else {
        this.page++;
       this.getChangList(this.listIndex+1)
      }
      // console.log("触发");
    },

    changeList(e) {
      this.page=1
      this.last_page = 0
      this.changList = []
      // console.log("aaaaaaa", e);
      this.listIndex = e.index;
      this.getChangList(e.index + 1);
    },

    goDetail(item) {
      // console.log(item, 1111111111);
      uni.navigateTo({
        url: `/pages/integral/customerDetail?id=${item.id}`,
      });
    },
    goFeed() {
      uni.navigateTo({
        url: `/pages/integral/feedback?phone=${this.phone}`,
      });
    },
    getChangList(num) {
      this.$http
        .helpKefuList({ type: num,page:this.page,p:20 })
        .then((res) => {
          // console.log(res.data.list, "常见问题");
          this.changList =this.changList.concat(res.data.list.data) ;
          this.last_page = res.data.list.last_page
          this.phone =  res.data.userInfo.phone
          // console.log(this.phone)
        })
        .catch((error) => {
          uni.$u.toast(error);
        });
    },
  },
};
</script>
      
      <style scoped lang="scss">
.content {
  position: fixed;
  box-sizing: border-box;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
}

.head {
  width: 100%;
  padding: 18rpx 30rpx 47rpx;
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .head_right {
    position: absolute;
    right: 30rpx;
    color: #55b877;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}

.box {
  padding: 30rpx;
  box-sizing: border-box;
  height: 100%;
  .box_view {
  }
  .box_item {
    margin-bottom: 48rpx;
    font-size: 30rpx;
    color: #eeeeee;
  }
}

.bottom {
  background: rgba(39, 39, 39, 0.5);
  padding: 16rpx 30rpx;
  box-sizing: border-box;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  .bottom_btn {
    background: linear-gradient(360deg, #50b674 0%, #aeddbd 100%);
    border-radius: 48rpx;
    height: 96rpx;
    text-align: center;
    line-height: 96rpx;
    color: #ffffff;
    font-size: 30rpx;
  }
}
.empty_view {
  margin-top: 300rpx;
  image {
    margin: 0 auto;
    width: 410rpx;
    height: 410rpx;
  }
  view {
    font-size: 30rpx;
    color: #d8d8d8;
    text-align: center;
  }
}
</style>